package common

import (
	"fmt"

	"github.com/gofiber/fiber/v3"
)

type ResponseBuilder struct {
	resp fiber.Map
}

func NewResponseBuilder() ResponseBuilder {
	return ResponseBuilder{resp: fiber.Map{
		"code":    200,
		"message": "ok",
	}}
}

func (r ResponseBuilder) Data(data any) ResponseBuilder {
	r.resp["data"] = data
	return r
}

func (r ResponseBuilder) Message(msg string) ResponseBuilder {
	r.resp["message"] = msg
	return r
}

func (r ResponseBuilder) ErrorMessage(err error) ResponseBuilder {
	r.Code(500)
	r.Message(fmt.Sprintf("error occur: %s", err))
	return r
}

func (r ResponseBuilder) Code(code int) ResponseBuilder {
	r.resp["code"] = code
	return r
}

func (r ResponseBuilder) Build() fiber.Map {
	return r.resp
}
